package com.wang.component;

import com.alipay.api.AlipayApiException;
import com.wang.enums.ProductOrderPayTypeEnum;
import com.wang.vo.PayInfoVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class PayFactory {
    @Autowired
    private AlipayStrategy alipayStrategy;

    @Autowired
    private WechatPayStrategy wechatPayStrategy;

    /**
     * 创建支付，普通工程模式
     * @param payInfoVO
     * @return
     */
    public String pay(PayInfoVO payInfoVO) throws AlipayApiException {
        String payType = payInfoVO.getPayType();

        if(payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALIPAY.name())){
            return alipayStrategy.orderPay(payInfoVO);
        } else if(payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT.name())){
            return wechatPayStrategy.orderPay(payInfoVO);
        }
        else{
            return "";
        }
    }

    /**
     * 查询订单是否支付成功
     * @param payInfoVO
     * @return
     */
    public String queryOrderSuccess(PayInfoVO payInfoVO){
        String payType = payInfoVO.getPayType();

        if(payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALIPAY.name())){
            return alipayStrategy.queryOrderSuccess(payInfoVO);
        } else if(payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT.name())){
            return wechatPayStrategy.queryOrderSuccess(payInfoVO);
        }
        else{
            return "暂不支持该查询方式";
        }
    }
}
